package 创建的方式;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class 方式三_Callable3 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Callable<Integer> c = new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                int res = 0;
                for (int i = 0; i < 1000; i++) {
                    res += i;
                }
                return res;
            }
        };
        FutureTask<Integer> f = new FutureTask<>(c);
        Thread t = new Thread(f);
        t.start();
        System.out.println(f.get());
    }
}
